package cn.lonecloud.util;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

/**
 * POI帮助类
 * 
 * @Title: ReadExcel.java
 * @Package cn.lonecloud.util
 * @Description:
 * @author lonecloud
 * @date 2016年10月27日 下午4:39:10
 */
@SuppressWarnings("unused")
public class ReadExcel {

	private static final Log LOG = LogFactory.getLog(ReadExcel.class);
	
	private Workbook wb;

	/**
	 * 获取文件类型
	 * 
	 * @Description:
	 * @param file
	 * @throws IOException
	 */
	@SuppressWarnings("resource")
	public void getWorkBook(File file) throws IOException {
		InputStream in = null;
		String type = FileUtil.getFileType(file);
		in = new FileInputStream(file);
		if ("xls".equals(type)) {
			LOG.debug("尝试使用xls读取");
			wb = new HSSFWorkbook(in);// xls类型
			if ("xlsx".equals(type)) {
				LOG.debug("尝试使用xlsx读取");
				wb = new XSSFWorkbook(in);// xlsx类型
			}
		} else {
			throw new IOException("您的文件名不正确");
		}
	}
	
}
